import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_syt/datas/goods_info_model.dart';
import 'package:flutter_syt/datas/message_model.dart';
import 'package:flutter_syt/domain/widgets/network_load_image.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/utils/web_socket_utility.dart';

class ServiceMessagesGoods extends StatelessWidget {
  final MessageModel model;
  ServiceMessagesGoods({required this.model});
  @override
  Widget build(BuildContext context) {
    GoodsInfoContentModel? contentModel;

    try {
      contentModel =
          GoodsInfoContentModel.fromJson(jsonDecode(model.content ?? ''));
      // goodsModel = GoodsInfoDataSource.goodsMap[contentModel.id ?? ''];
    } catch (e) {}

    return contentModel == null
        ? Container()
        : Container(
            padding: EdgeInsets.all(12),
            decoration: BoxDecoration(
              // color:
              border: Border.all(color: Color(0xffCCCCCC), width: 1),
              borderRadius: model.direction == MessageDirection.RECEIVE
                  ? BorderRadius.only(
                      bottomLeft: Radius.circular(12),
                      bottomRight: Radius.circular(12),
                      topRight: Radius.circular(12))
                  : BorderRadius.only(
                      bottomLeft: Radius.circular(12),
                      bottomRight: Radius.circular(12),
                      topLeft: Radius.circular(12)),
            ),
            height: 114.w,
            width: 300.w,
            child: Row(
              children: [
                ClipRRect(
                  borderRadius: BorderRadius.circular(4),
                  child: NetworkLoadImage.loadNetworkImage(contentModel.picUrl,
                      width: 90.w, height: 90.w),
                ),
                SizedBox(
                  width: 10.w,
                ),
                Expanded(
                    child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                        alignment: Alignment.centerLeft,
                        constraints: BoxConstraints(maxWidth: 212.w),
                        child: Text(
                          contentModel.name ?? '',
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(fontSize: 16),
                        )),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        RichText(
                          textAlign: TextAlign.left,
                          text: TextSpan(
                            children: contentModel.type == '2'
                                ? [
                                    TextSpan(
                                      text: "${contentModel.price}",
                                      style: (TextStyle(
                                        fontWeight: FontWeight.w500,
                                        fontSize: 16,
                                        color: Color(0xFFFF5700),
                                      )),
                                    ),
                                    TextSpan(
                                      text: S.current.service_point,
                                      style: (TextStyle(
                                        fontWeight: FontWeight.w500,
                                        fontSize: 12,
                                        color: Color(0xFFFF5700),
                                      )),
                                    ),
                                  ]
                                : [
                                    TextSpan(
                                      text: "￥",
                                      style: (TextStyle(
                                        fontWeight: FontWeight.w500,
                                        fontSize: 12,
                                        color: Color(0xFFFF5700),
                                      )),
                                    ),
                                    TextSpan(
                                      text: "${contentModel.price}",
                                      style: (TextStyle(
                                        fontWeight: FontWeight.w500,
                                        fontSize: 16,
                                        color: Color(0xFFFF5700),
                                      )),
                                    ),
                                  ],
                          ),
                        ),
                      ],
                    )
                  ],
                ))
              ],
            ),
          );
  }
}

// class GoodsInfoDataSource {
//   static Map<String, GoodsInfoModel?> goodsMap = {};
// }
